package com.gf.controller.shop;

import com.alibaba.fastjson.JSONObject;
import com.gf.bean.Shop;
import com.gf.service.impl.ShopServiceImpl;
import com.gf.utils.Const;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "CheckshopnameServlet",urlPatterns ="/checkshopname")
public class CheckshopnameServlet extends HttpServlet {
    static ShopServiceImpl shopimpl = null;
    static {
        shopimpl=new ShopServiceImpl();


    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setHeader("Pragma", "No-cache");
        response.setDateHeader("Expires", 0);
        response.setHeader("Cache-Control", "no-cache");
        String shopname = request.getParameter("shopname");
        Shop shop = shopimpl.selectshopname(shopname);
        PrintWriter out = response.getWriter();
        JSONObject obj = new JSONObject();
        if (shop==null){
            response.setStatus(200);
            obj.put("status", 200);
            obj.put("message", Const.NOSHOPNAME);
        }else{
            response.setStatus(300);
            obj.put("status", 300);
            obj.put("message", Const.HADSHOPNAME);

        }
        out.println(JSONObject.toJSON(obj));
        out.flush();
        out.close();


    }
}
